home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
parallax
/
more_exa.tar
/
more
/
Vision
/
mk3d.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-18
|
3KB
|
112 lines
/*******************************************************************************/
/* File : mk3d.c */
/* */
/* Function : to take the left and right image of a picture and overlays them*/
/* to one image : */
/* The original black&white pixel of the left image turns to red. */
/* The original b&w pixel of the right image turns to green. */
/* With red-green glasses now you can watch the picture */
/* in 3-D. */
/* */
/* Author : Michael C. Ancutici */
/* */
/* Date : 12.09.91 */
/*******************************************************************************/
#include <stdio.h>
FILE *inl, *inr , *out ;
int heigth, width, i, j , white;
char hl, hr, h1, h2 ;
char black = (char)( 0 );
int backgr;
int BLACK = 0;
int WHITE = 1;
char input_name_l[100] , input_name_r[100] , output_name[100] , help[100];
main( argc , argv )
int argc ;
char *argv[] ;
{
if( argc == 1 || argc > 3)
{
printf("\n Usage: mk3d [b] <filename>\n" ) ;
printf( " - filename without extension .l.ppm or .r.ppm\n" ) ;
printf( " - b for black background (additiv)\n");
printf( " - default background is white (subtractive)\n");
exit(20) ;
}
strcpy( help , argv[1]) ;
if (argc == 3 && help[0] == 'b' && help[1] == (char)( 0 ) )
backgr = BLACK;
else
backgr = WHITE;
if (argc == 3)
strcpy( input_name_l , argv[2] ) ;
else
strcpy( input_name_l , argv[1] ) ;
strcpy( output_name , input_name_l ) ;
strcpy( input_name_r , input_name_l ) ;
strcat( output_name , ".3d.ppm" ) ;
strcat( input_name_l , ".l.ppm" ) ;
strcat( input_name_r , ".r.ppm" ) ;
if( !(inl = fopen( input_name_l , "r" )))
{ printf("\n ERROR: Cound not open input file %s !\n",input_name_l ) ; exit(20) ; }
if( !(inr = fopen( input_name_r , "r" )))
{ printf("\n ERROR: Cound not open input file %s !\n",input_name_r ) ; exit(20) ; }
if( !(out = fopen( output_name , "w" )))
{ printf("\n ERROR: Cound not open output file %s !\n",output_name ) ; exit(20) ; }
fgets(help , 100 , inr);
fprintf( out , help ) ;
fscanf( inr , "%d\n%d\n%d\n" , &width , &heigth , &white ) ;
fprintf( out , "%1d\n%1d\n%1d\n" ,width+1, heigth+1, white ) ;
for( i=1 ; i<5 ; ++i)
fgets(help , 100 , inl);
for( i=0 ; i<heigth+1 ; ++i )
{
for( j=0 ; j<width+1 ; ++j )
{
if (j == width | i == heigth)
hl = black;
else
fscanf(inl, "%c%c%c" , &hl, &h1, &h2 );
if (j == 0 | i == 0 )
hr = black;
else
fscanf(inr, "%c%c%c" , &hr, &h1, &h2 );
if (backgr == WHITE) {
if (hl == black && hr == black)
fprintf(out, "%c%c%c", white, white, white);
else
fprintf(out, "%c%c%c", white-hl, white-hr, black);
}
else
fprintf(out, "%c%c%c",hl, hr, black);
}
}
fclose( inl ) ;
fclose( inr ) ;
fclose( out ) ;
}